
import { getStorage, setStorage, removeStorage } from '@/utils/storage';
import { getCos } from '@/api/cos';
const baseUrl = process.env.VUE_APP_API_URL
const state = {
	login_visible: false,
	auth_visible: false,
	live_pay_visible: false,
	cos_info: getStorage('cos_info') ? JSON.parse(getStorage('cos_info')) : null,
	uploadApi: baseUrl + '/upload/create',
	contacters: [],
	drop: false,
	message: null,
	loaded: false,
	coin_name:'',//金币名称
}
const mutations = {
	SHOW_LOGIN: (state) => {
		state.login_visible = true
	},
	SHOW_AUTH: (state) => {
		state.auth_visible = true
	},
	CACHE_COS: (state, data) => {
		state.cos_info = data
		setStorage('cos_info', JSON.stringify(data), 1800)
	},
	COIN_NAME: (state, data) => {
		state.coin_name = data
	},
}
const actions = {
	showLogin ({ commit }) {
		commit('SHOW_LOGIN')
	},
	showAuth ({ commit }) {
		commit('SHOW_AUTH')
	},
	cosInfo ({ commit, state }) {
		return new Promise((resolve, reject) => {
			getCos().then(response => {
				commit('CACHE_COS', response)
				resolve(response)
			}).catch(error => {
				reject(error)
			})
		})
	},
	coinName ({ commit,state },data) {
		commit('COIN_NAME',data)
	},
	

}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
